package com.ruoyi.system.domain;

import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

import java.util.Date;

/**
 * 报名管理信息对象 sys_positions_apply
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
public class SysPositionsApply extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 报名ID */
    private Long applyId;

    /** 报名用户id */
    @Excel(name = "报名用户id")
    private Long userId;

    /** 用户单位id */
    @Excel(name = "用户单位id")
    private Long deptId;

    /** 用户名 */
    @Excel(name = "用户名")
    private String userName;

    /** 用户姓名 */
    @Excel(name = "用户姓名")
    private String nickName;

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    /** 用户身份证号 */
    @Excel(name = "用户身份证号")
    private String idcard;

    /** 批次编号 */
    @Excel(name = "批次编号")
    private String batchNumber;

    /** 岗位编号 */
    @Excel(name = "岗位编号")
    private String positionCode;

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    /** 岗位名称 */
    @Excel(name = "岗位名称")
    private String companyName;

    /** 岗位性质 */
    @Excel(name = "岗位性质")
    private String positionNature;

    public String getPositionNature() {
        return positionNature;
    }

    public void setPositionNature(String positionNature) {
        this.positionNature = positionNature;
    }

    /** 公司名称 */
    @Excel(name = "公司名称")
    private String positionName;

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    /** 工作地点 */
    @Excel(name = "工作地点")
    private String location;

    /** 一级审核情况（0为未审核，1为通过，2为不通过） */
    @Excel(name = "审核情况", readConverterExp = "0=未审核,1=通过,2=不通过")
    private Long statusApply;

    /** 流程id */
    @Excel(name = "流程id")
    private String processId;


    /** 退回原因（自动审核员姓名和退回原因） */
    @Excel(name = "退回原因", readConverterExp = "自=动审核员姓名和退回原因")
    private String returnReason;



//    /** 创建时间 */
//    @Excel(name = "创建时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
//    private Date createTime;
//
//    @Override
//    public Date getCreateTime() {
//        return createTime;
//    }

    public void setApplyId(Long applyId)
    {
        this.applyId = applyId;
    }

    public Long getApplyId() 
    {
        return applyId;
    }

    public void setUserId(Long userId)
    {
        this.userId = userId;
    }

    public Long getUserId()
    {
        return userId;
    }

    public void setDeptId(Long deptId) 
    {
        this.deptId = deptId;
    }

    public Long getDeptId() 
    {
        return deptId;
    }

    public void setUserName(String userName) 
    {
        this.userName = userName;
    }

    public String getUserName() 
    {
        return userName;
    }

    public void setIdcard(String idcard) 
    {
        this.idcard = idcard;
    }

    public String getIdcard() 
    {
        return idcard;
    }

    public void setBatchNumber(String batchNumber) 
    {
        this.batchNumber = batchNumber;
    }

    public String getBatchNumber() 
    {
        return batchNumber;
    }

    public void setPositionCode(String positionCode) 
    {
        this.positionCode = positionCode;
    }

    public String getPositionCode() 
    {
        return positionCode;
    }

    public void setPositionName(String positionName) 
    {
        this.positionName = positionName;
    }

    public String getPositionName() 
    {
        return positionName;
    }



    public void setReturnReason(String returnReason) 
    {
        this.returnReason = returnReason;
    }

    public String getReturnReason() 
    {
        return returnReason;
    }

    // 添加计算年龄的方法
    public String getUserAge() {
        if (this.idcard != null && this.idcard.length() >= 14) {
            try {
                // 从身份证号中提取出生日期
                String birthYearStr = "";
                String birthMonthStr = "";
                String birthDayStr = "";

                if (this.idcard.length() == 18) {
                    // 18位身份证号
                    birthYearStr = this.idcard.substring(6, 10);
                    birthMonthStr = this.idcard.substring(10, 12);
                    birthDayStr = this.idcard.substring(12, 14);
                } else if (this.idcard.length() == 15) {
                    // 15位身份证号
                    birthYearStr = "19" + this.idcard.substring(6, 8);
                    birthMonthStr = this.idcard.substring(8, 10);
                    birthDayStr = this.idcard.substring(10, 12);
                }

                // 计算年龄
                int birthYear = Integer.parseInt(birthYearStr);
                int birthMonth = Integer.parseInt(birthMonthStr);
                int birthDay = Integer.parseInt(birthDayStr);

                // 获取当前日期
                java.util.Calendar now = java.util.Calendar.getInstance();
                int currentYear = now.get(java.util.Calendar.YEAR);
                int currentMonth = now.get(java.util.Calendar.MONTH) + 1;
                int currentDay = now.get(java.util.Calendar.DAY_OF_MONTH);

                // 计算年龄
                int age = currentYear - birthYear;

                // 如果还没过生日，则年龄减1
                if (currentMonth < birthMonth || (currentMonth == birthMonth && currentDay < birthDay)) {
                    age--;
                }

                return String.valueOf(age);
            } catch (Exception e) {
                // 身份证号格式不正确时返回null或默认值
                return null;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("applyId", getApplyId())
            .append("userId", getUserId())
            .append("deptId", getDeptId())
            .append("userName", getUserName())
            .append("idcard", getIdcard())
            .append("batchNumber", getBatchNumber())
            .append("positionCode", getPositionCode())
            .append("companyName", getCompanyName())
            .append("positionName", getPositionName())
            .append("statusApply", getStatusApply())
            .append("processId", getProcessId())
            .append("returnReason", getReturnReason())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .toString();
    }

    public Long getStatusApply() {
        return statusApply;
    }

    public void setStatusApply(Long statusApply) {
        this.statusApply = statusApply;
    }

    public String getProcessId() {
        return processId;
    }

    public void setProcessId(String processId) {
        this.processId = processId;
    }
}
